<#import "../../layout/single.ftl" as layout>
<@layout.single title="${(action=='todo')?string('我的待办','我的已办')}" css=["css/plugins/bootstrap-table/bootstrap-table.min.css","css/plugins/steps/jquery.steps.css"] javascripts=["plugins/bootstrap-table/bootstrap-table.min.js","plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js","plugins/layui/layer/layer.js","plugins/steps/jquery.steps.js"]>
<div class="container-fluid">
    <div class="wrapper wrapper-content">
        <div class="col-sm-12 animated fadeInRight">
            <div class="row">
                <div class="col-sm-12" id="task-datas" style="margin-left: -15px;">
                    <table id="table" data-toggle="table" data-id-field="taskId"
                           data-url="${request.contextPath}/flow/tasks/${action}" data-side-pagination="server"
                           data-pagination="true" data-page-size="${Application.pageSize}" data-type="json">
                        <thead>
                        <tr>
                            <th data-field="state" data-checkbox="true"></th>
                            <th data-field="taskName" data-sortable="true" data-formatter="datatablesfn.setFontWeight">
                                任务名称
                            </th>
                            <th data-field="modelName">业务类型</th>
                            <#if action=="todo">
                                <th data-field="status" data-formatter="datatablesfn.showStatus">流程状态</th>
                                <th data-field="createUser" data-formatter="datatablesfn.showUser">发起用户</th>
                                <th data-field="createTimeStr" data-sortable="true">发起时间</th>
                                <th data-field="delegated" data-formatter="showDelegateInfo">任务信息</th>
                            <#elseif action=="done">
                                <th data-field="endTimeStr" data-sortable="true">办理时间</th>
                                <th data-field="comment">备注说明</th>
                            </#if>
                            <th data-formatter="showDetail" data-field="taskId">操作</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    var $table = $('#table');

    function showDetail(value, row, index) {
        var html = [];
        html.push("<div class='pull-right'>");
        if (row.status == "UNFINISHED") {

            html.push("<a href='javascript:void(0);' onclick='task.todoTask(" + value + ");' class='btn btn-primary'>办 理</a>");
            html.push("&nbsp;&nbsp;");
            if (!row.delegated) {
                html.push("<a href='javascript:void(0);' onclick='task.delegate(" + value + ");' class='btn btn-warning'>委 托</a>");
                html.push("&nbsp;&nbsp;");
            }
            html.push("<a href='javascript:void(0);' onclick='task.detail(" + value + ");' class='btn btn-info'>详 情</a>");
        } else {
            html.push("<a href='javascript:void(0);' onclick='task.detail(" + row.processInstanceId + ",true);' class='btn btn-info'>详 情</a>");
        }
        html.push("</div>");
        return html.join("");
    }

    function showDelegateInfo(value, row) {
        var html = "";
        if (value) {
            html = "该任务由 <strong>" + row.owner.userName + "</strong> 委托办理";
        }
        return html;
    }


</script>
</@layout.single>